package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.PageRequestDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/3/16 10:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult channel() {
        LambdaQueryWrapper<WmChannel> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WmChannel::getStatus, WemediaConstants.Channel_TYPE_MEDIA);
        return ResponseResult.okResult(wmChannelService.list(wrapper));
    }

    @PostMapping("/channels")
    public ResponseResult listAll(@RequestBody WmChannelDto dto){
        return wmChannelService.findAll(dto);
    }

    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannelDto dto){
        return wmChannelService.add(dto);
    }



    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannelDto dto){
        return wmChannelService.revise(dto);
    }

    @GetMapping("/del/{id}")
    public ResponseResult remove(@PathVariable Integer id){
        return wmChannelService.remove(id);
    }
}